package config

import (
	"fmt"
	"os"
	"path"

	"gopkg.in/yaml.v2"
)

type BaseConfig struct {
	Gin struct {
		Port       int
		Host       string
		TouristUrl []string `yaml:"tourist-url"`
		Upload     struct {
			Path string
		}
		Db struct {
			Mysql struct {
				Url   string
				Debug bool
			}
		}
	}
}

var (
	config *BaseConfig
)

func LoadConfig() (*BaseConfig, error) {
	if config != nil {
		return config, nil
	}
	getwd, _ := os.Getwd()
	ConfigPath := path.Join(getwd, "config")
	open, err := os.Open(path.Join(ConfigPath, "application.yml"))
	defer open.Close()
	err = yaml.NewDecoder(open).Decode(&config)
	fmt.Println(config)
	return config, err
}
